package com.yczy365.petmall.service.impl;

import com.yczy365.petmall.ex.ServiceException;
import com.yczy365.petmall.mapper.AlbumMapper;
import com.yczy365.petmall.pojo.dto.AlbumAddNewDTO;
import com.yczy365.petmall.pojo.entity.Album;
import com.yczy365.petmall.service.AlbumService;
import com.yczy365.petmall.web.ServiceCode;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AlbumServiceImpl implements AlbumService {
    @Autowired
    private AlbumMapper mapper;
    @Override
    public void addNew(AlbumAddNewDTO albumAddNewDTO) {
        int i = mapper.countByNameAndId(albumAddNewDTO.getName());
        if (i>0){
            throw new ServiceException("名称被占用！",ServiceCode.ERR_CONFLICT);
        }
        Album album = new Album();
        BeanUtils.copyProperties(albumAddNewDTO,album);
        mapper.insertAlbum(album);
    }
}
